<html>
<head><meta charset="utf-8"><title>surprising external crates with the json output format · rustdoc · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/index.html">rustdoc</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/surprising.20external.20crates.20with.20the.20json.20output.20format.html">surprising external crates with the json output format</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="247806636"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/surprising%20external%20crates%20with%20the%20json%20output%20format/near/247806636" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Urgau <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/surprising.20external.20crates.20with.20the.20json.20output.20format.html#247806636">(Jul 31 2021 at 14:26)</a>:</h4>
<p>Hello, I was experimenting with <code>rustdoc</code> and it's json output format when I realized that for a 5 lines <code>lib.rs</code>produce over 23000 lines of json when I open it I saw the entire standard library (<code>core</code>, <code>alloc</code>, <code>std</code>, ...) but also some internal crates like <code>rustc_std_workspace_alloc</code>, <code>rust_std_workspace_core</code> but also <code>rustc_demangle</code>. Is that expected ?</p>



<a name="247815359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/surprising%20external%20crates%20with%20the%20json%20output%20format/near/247815359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/surprising.20external.20crates.20with.20the.20json.20output.20format.html#247815359">(Jul 31 2021 at 17:25)</a>:</h4>
<p>Hmm, it does seem weird that it includes items from other crates</p>



<a name="247815377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/surprising%20external%20crates%20with%20the%20json%20output%20format/near/247815377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/surprising.20external.20crates.20with.20the.20json.20output.20format.html#247815377">(Jul 31 2021 at 17:25)</a>:</h4>
<p><span class="user-mention" data-user-id="268539">@Nixon Enraght-Moony</span> <span class="user-mention" data-user-id="319144">@CraftSpider</span> <span class="user-mention" data-user-id="310818">@Joseph Ryan</span> do one of you happen to remember why rustdoc does that? Or is it unintentional?</p>



<a name="247817421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/surprising%20external%20crates%20with%20the%20json%20output%20format/near/247817421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joseph Ryan <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/surprising.20external.20crates.20with.20the.20json.20output.20format.html#247817421">(Jul 31 2021 at 18:12)</a>:</h4>
<p>Yeah so the reason that the output is so bloated right now is that it takes ALL items in scope (so everything in the prelude and transitively referenced by any external crate that you bring into scope) and includes them in the output. The affected fields are <code>index</code> which is supposed to include the full trait definition for any trait used (even if it's from an external crate) and <code>paths</code> which contains the full module path of any item referenced.</p>
<p>The correct thing to do which we didn't get around to on the first pass implementation was to write a visitor that would figure out which items were actually "reachable" by following all <code>id</code> references from the crate root and only including those in the output. While the output would still contain stuff like blanket impls from std and external crates, it would definitely make the resulting blob much much smaller.</p>



<a name="247817582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/surprising%20external%20crates%20with%20the%20json%20output%20format/near/247817582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joseph Ryan <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/surprising.20external.20crates.20with.20the.20json.20output.20format.html#247817582">(Jul 31 2021 at 18:16)</a>:</h4>
<p>Since removing unreachable output won't change any functionality it shouldn't be too hard to go ahead and write this pruning pass without messing with other parts of the code, if I have some time this week I'll try to make a pass at it, but if anyone else would like to I can walk you through it as well. I'd definitely like to be able to open the json output in my editor instead of poking at it with <code>jq</code> due to it's size <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>